<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text"
        placeholder="enter the name you search"
        v-model="searchKey"
      />&nbsp;<button @click="queryUserListHandle">Search</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";

export default {
  name: "Header",
  props: ["setState"],
  data() {
    return {
      searchKey: "",
    };
  },
  methods: {
    async queryUserListHandle() {
      /* 将状态设置为搜索中 */
      this.setState({ isInit: false, isSearch: true });
      const {
        data: { items },
      } = await axios.get(
        `https://api.github.com/search/users?q=${this.searchKey}`
      );
      console.log(items);
      this.setState({isSearch: false, userList: items})
    },
  },
};
</script>

<style>
</style>